#include "queue.h"

//向队列中添加元素
int enQueue(queue_t *p,int net_fd){
    node_t *q = (node_t*)malloc(sizeof(node_t));
    q->net_fd = net_fd;
    if(q == NULL){
        fprintf(stdout,"malloc failed");
    }

    if(p->size == 0){
        p->head = q;
        p->rear = q;
    }else{
       p->rear->pNext = q;
       p->rear = q;
    }

    p->size++;
    return 0;
}

int deQueue(queue_t* p){
    if(p->size == 0){
        return -1;
    }    
    node_t *q = p->head;
    p->head = q->pNext;

    if(p->size==1){
        p->rear=NULL;
    }
    p->size--;

    free(q);

    return 0;
}

